let btns = document.querySelectorAll(".item-img");
console.log(btns);
let input = document.querySelectorAll(".item-main");
console.log(input);
btns.forEach(function (v, i) {
    v.onclick = function () {
        input[i].value = "";
        v.style.display = "none";
    }
});
input.forEach(function (v, i) {
    v.oninput = function () {
        if (v.value.length >= 1) {
            btns[i].style.display = "block";
        } else {
            btns[i].style.display = "none";
        }
    }
    v.onfocus = function () {
        v.style.border = "1px solid #15bded"
    }
});
/*注册正则*/
let regArr = [
    /^[a-zA-Z]\w{5,11}$/, //6-12: 字母开头,后面跟字母\数字\下划线
    /^1[3456789][0-9]{9}$/, //11  : 
    /^[a-zA-Z]\w{3}$/, //4位验证码: 字母开头,后面跟字母\数字\下划线
    /^[a-zA-Z]\w{5,11}$/ //6-12: 字母开头,后面跟字母\数字\下划线
];
let warnArr = document.querySelectorAll(".warning");
console.log(warnArr);
input.forEach(function (v, i) {
    v.onblur = function () {
        v.style.border = "1px solid #ccc"
        if (regArr[i].test(v.value) === false) {
            warnArr[i].style.display = "block"
        } else {
            warnArr[i].style.display = "none"
        }

    }
});
let ckbox = document.querySelector(".ckbox");

let btn = document.querySelector(".btn");

ckbox.onclick = function () {
    if (this.checked) {
        btn.style.backgroundColor = "#00bdff";
        btn.style.color = "#fff";
        btn.disabled = false;
    } else {
        btn.style.backgroundColor = "#ccc";
        btn.style.color = "#000";
        btn.disabled = true;
    }
}
btn.onclick = function () {
    let flag = true;
    console.log("点击");
    input.forEach(function (v, i) {
        console.log(i, regArr[i].test(v.value))
        if (regArr[i].test(v.value)) {
            warnArr[i].style.display = "none"
        } else {
            warnArr[i].style.display = "block"
            flag = "false";
        }
    });

    if (flag) {
        alert("恭喜，注册成功")
        location.href = "../pages/login.html"
    };
}